<?php
/**
  * //w/w/w.s/h/u/o/t//u/p/u c/o/m  说 图/谱/源/码/分/享
 */
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/17 0017
 * Time: 16:42
 */
defined("IN_IA")or exit("Access Denied");
global $_W,$_GPC;
$uniacid=$_GPC['uniacid'];
$op=$_GPC['op'] ? $_GPC['op'] : "index";
$uid=$_GPC['uid'];

//查询组团商品信息
if($op=='getGroupGoods'){
    $request=array();
    if(!empty($_GPC['page'])){
        $page=intval($_GPC['page'])+1;
    }else{
        $page=1;
    }

    $condition=array(
        'uniacid'=>$uniacid,
        'is_put_away'=>1,
    );  
    
    $goodsData=pdo_getall('cqkundian_farm_group_goods',$condition,'','','rank desc',array($page,10));
    //查询该商品的规格值
    for($i=0;$i<count($goodsData);$i++){
        $specItem=pdo_getall('cqkundian_farm_group_goods_spec',array('goods_id'=>$goodsData[$i]['id'],'uniacid'=>$uniacid));
        if($specItem){
            $priceArr=array();
            for($j=0;$j<count($specItem);$j++){
                $priceArr[]=$specItem[$j]['price'];
            }
            $goodsData[$i]['min_price']=min($priceArr);
            $goodsData[$i]['max_price']=max($priceArr);
        }else{
            $goodsData[$i]['min_price']=$goodsData[$i]['price'];
            $goodsData[$i]['max_price']=$goodsData[$i]['price'];
        }
    }
    $request['goodsData']=$goodsData;
    echo json_encode($request);die;
}

//查看商品详情页
if($op=='getGroupDetail'){
    $request=array();
    $goods_id=$_GPC['goods_id'];
    $goodsData=pdo_get('cqkundian_farm_group_goods',array('uniacid'=>$uniacid,'id'=>$goods_id));
    $goodsData['goods_slide']=unserialize($goodsData['goods_slide']);
    $goodsData['send_goods_desc']=unserialize($goodsData['send_goods_desc']);

    //获取最高价和最低价
    $goodsSpec=pdo_getall('cqkundian_farm_group_goods_spec',array('goods_id'=>$goodsData['id'],'uniacid'=>$uniacid));
    if($goodsSpec){
        $priceArr=array();
        for($j=0;$j<count($goodsSpec);$j++){
            $priceArr[]=$goodsSpec[$j]['price'];
        }
        $goodsData['min_price']=min($priceArr);
        $goodsData['max_price']=max($priceArr);    
    }else{
        $goodsData['min_price']=$goodsData['price'];
        $goodsData['max_price']=$goodsData['price'];    
    }
    
    //查询商品的规格信息
    $specItem=pdo_getall('cqkundian_farm_group_spec',array('uniacid'=>$uniacid,'goods_id'=>$goods_id));
    for($i=0;$i<count($specItem);$i++){
        $specVal=pdo_getall('cqkundian_farm_group_spec_value',array('spec_id'=>$specItem[$i]['id'],'uniacid'=>$uniacid));
        for($j=0;$j<count($specVal);$j++){
            $specVal[$j]['is_select']=0;    //是否选中该规格
            $specVal[$j]['is_count']=1;     //库存足够
        }
        $specItem[$i]['specVal']=$specVal;
        $specItem[$i]['is_select']=0;
    }
    $request['goodsData']=$goodsData;
    $request['specItem']=$specItem;
    //关于我们
    $aboutData=pdo_get('cqkundian_farm_about',array('uniacid'=>$uniacid));
    $request['aboutData']=$aboutData;
    echo json_encode($request);die;
}

//选中商品规格
if($op=='getGroupSpec'){
    $request=array();
    $spec_id_str=$_GPC['spec_id'];
    $spec_id_arr=explode("_", $spec_id_str);
    $goods_id=$_GPC['goods_id'];
    sort($spec_id_arr);
    $goodsData=pdo_get('cqkundian_farm_group_goods',array('id'=>$goods_id,'uniacid'=>$uniacid));
    $specItem=pdo_getall('cqkundian_farm_group_spec_value',array('id in'=>$spec_id_arr));
    $sku_name_arr=array();
    for($i=0;$i<count($specItem);$i++){
        $sku_name_arr[]=$specItem[$i]['spec_value'];
    }
    $sku_name_str=implode('+',$sku_name_arr);
    $sku_name=implode(',', $spec_id_arr);
    $specVal=pdo_get('cqkundian_farm_group_goods_spec',array('sku_name'=>$sku_name,'goods_id'=>$goods_id,'uniacid'=>$uniacid));
    if($specVal){       //存在该规格
        //判断该规格的库存是否大于0
        if($specVal['spec_src']==''){
            $specVal['spec_src']=$goodsData['cover'];
        }
        if($specVal['count']>=1){
            $request['code']=1;
        }else{
            $request['code']=2;
        }
        $request['specVal']=$specVal;
    }else{
        $request['code']=3;
    }
    $request['sku_name_str']=$sku_name_str;
    echo json_encode($request);die;
}

//确认订单
if($op=='getSureGoodsData'){
    $request=array();
    $goods_id=$_GPC['goods_id'];
    $spec_id=$_GPC['spec_id'];
    $goodsData=pdo_get('cqkundian_farm_group_goods',array('id'=>$goods_id,'uniacid'=>$uniacid));
    $specItem=pdo_getall('cqkundian_farm_group_spec',array('goods_id'=>$goods_id,'uniacid'=>$uniacid));
    $specVal=pdo_get('cqkundian_farm_group_goods_spec',array('goods_id'=>$goods_id,'id'=>$spec_id,'uniacid'=>$uniacid));
    $spec_id_arr=explode(',',$specVal['sku_name']);
    for ($i=0; $i <count($spec_id_arr) ; $i++) { 
        $spec_val=pdo_get('cqkundian_farm_group_spec_value',array('id'=>$spec_id_arr[$i],'uniacid'=>$uniacid));
        for ($j=0; $j <count($specItem) ; $j++) { 
            if($specItem[$j]['id']==$spec_val['spec_id']){
                $specItem[$i]['spec_val']=$spec_val['spec_value'];
            }
        }
    }

    $total_price=0;
    if($specVal){
        $total_price=$specVal['price']*$_GPC['count'];
    }else{
        $total_price=$goodsData['price']*$_GPC['count'];
    }

    //查询优惠券
    $couponCount=0;
    $userCoupon=pdo_getall('cqkundian_farm_user_coupon',array('uniacid'=>$uniacid,'uid'=>$uid,'status'=>0));
    if(!empty($userCoupon)) {
        for ($i = 0; $i < count($userCoupon); $i++) {
            $coupon = pdo_get('cqkundian_farm_shop_coupon', array('uniacid' => $uniacid, 'id' => $userCoupon[$i]['cid'], 'type' => 2));
            //优惠券是否过期
            if ($coupon['expiry_date'] == 1) {
                if (($userCoupon[$i]['create_time'] + ($coupon['expiry_day'] * 86400)) > time()) {
                    if ($coupon['low_cash_price'] < $total_price) {  //判断订单金额是否大于优惠消费最低金额
                        $couponCount += 1;
                    }
                }
            } else {
                if (time() > $coupon['begin_time'] && time() < $coupon['end_time']) {
                    if ($coupon['low_cash_price'] < $total_price) {  //判断订单金额是否大于优惠消费最低金额
                        $couponCount += 1;
                    }
                }
            }
        }
    }
    $request['couponCount']=$couponCount;

    //查询快递运费
    $aboutData=pdo_get('cqkundian_farm_about',array('uniacid'=>$uniacid));
    $request['specItem']=$specItem;
    $request['goodsData']=$goodsData;
    $request['aboutData']=$aboutData;
    if($specVal){
        $request['total_price']=$total_price+$goodsData['send_price'];
    }else{
        $request['total_price']=$total_price+$goodsData['send_price'];
    }
    
    $request['specVal']=$specVal;

    echo json_encode($request);die;
}


//生成订单
if($op=='addGroupOrder'){
    $address=$_GPC['address'];
    $phone=$_GPC['phone'];
    $name=$_GPC['name'];
    $state=$_GPC['state'];      //是否开启加工
    $is_add=$_GPC['is_add'];    //加工成 1腊肉 2香肠
    $goods_id=$_GPC['goods_id'];
    $spec_id=$_GPC['spec_id'];
    $remark=$_GPC['remark'];
    $count=$_GPC['count'];

    $coupon_id=$_GPC['coupon_id'];
    $coupon_price=$_GPC['coupon_price'];

    $aboutData=pdo_get('cqkundian_farm_about',array('uniacid'=>$uniacid));
    $goodsData=pdo_get('cqkundian_farm_group_goods',array('id'=>$goods_id,'uniacid'=>$uniacid));

    include 'function.inc.php';
    $farmSetData=getFarmSetData(array('is_open_distribution','distribution_one_price','distribution_two_price'),array('uniacid'=>$uniacid));

    $insertOrder=array(
        'order_number'=>rand(100,999).time().rand(100,999),
        'uid'=>$uid,
        'name'=>$name,
        'address'=>$address,
        'phone'=>$phone,
        'create_time'=>time(),
        'status'=>0,      //未支付
        'remark'=>$remark,
        'uniacid'=>$uniacid,
        'send_price'=>$goodsData['send_price'],
        'body'=>$goodsData['goods_name']." 等商品",
        'coupon_id'=>$coupon_id,
        'coupon_price'=>$coupon_price,
    );
    
    //判断商品是否存在规格
    if($goodsData['is_open_sku']==1){
        $specVal=pdo_get('cqkundian_farm_group_goods_spec',array('goods_id'=>$goods_id,'id'=>$spec_id,'uniacid'=>$uniacid));
        //是否需要加工
        if($is_add){
            $insertOrder['is_add']=$is_add;                         //    加工
            $price=$specVal['price']*$count;
            $total_price=$price*(1+($aboutData['add_price']/100));  //加上加工费
            $total_price+=$goodsData['send_price'];                 //加上运费
            $insertOrder['total_price']=$total_price;
            $insertOrder['add_price']=$price*($aboutData['add_price']/100);     //加工费

        }else{
            $insertOrder['is_add']=0;
            $insertOrder['total_price']=$specVal['price']*$count+$goodsData['send_price'];
        }
        if($coupon_id && $coupon_price){
            $insertOrder['total_price']=$insertOrder['total_price']-$coupon_price;  //优惠券抵用
        }

        //是否开启分销
        if($farmSetData['is_open_distribution']==1){
            $user=pdo_get('cqkundian_farm_user',array('uniacid'=>$uniacid,'uid'=>$uid));
            //当前下单用户的一级分销商
            if($user['one_distributor']!=0) {
                $insertOrder['is_price']=1;
                $one_sale = pdo_get('cqkundian_farm_user', array('uniacid' => $uniacid, 'uid' => $user['one_distributor']));
                $insertOrder['one_price']=round($insertOrder['total_price']*($farmSetData['distribution_one_price']/100),2);
                if($one_sale['one_distributor']!=0){
                    $insertOrder['two_price']=round($insertOrder['total_price']*($farmSetData['distribution_two_price']/100),2);
                }
            }
        }

        $order_res=pdo_insert('cqkundian_farm_group_order',$insertOrder);
        $order_id=pdo_insertid();
        //商品详情
        $insertDetail=array(
            'goods_id'=>$goods_id,
            'order_id'=>$order_id,
            'goods_name'=>$goodsData['goods_name'],
            'price'=>$specVal['price'],
            'count'=>$count,
            'spec_id'=>$spec_id,
            'uniacid'=>$uniacid,
        );
        if($specVal['spec_src']){
            $insertDetail['cover']=$specVal['spec_src'];
        }else{
            $insertDetail['cover']=$goodsData['cover'];
        }
    }else{
        //是否需要加工
        if($state){
            $insertOrder['is_add']=$is_add;                         //    加工
            $price=$goodsData['price']*$count;
            $total_price=$price*(1+($aboutData['add_price']/100));  //加上加工费
            $total_price+=$goodsData['send_price'];                 //加上运费
            $insertOrder['total_price']=$total_price;
            $insertOrder['add_price']=$price*($aboutData['add_price']/100);     //加工费
        }else{
            $insertOrder['is_add']=0;
            $insertOrder['total_price']=$goodsData['price']*$count+$goodsData['send_price'];
        }
        if($coupon_id && $coupon_price){
            $insertOrder['total_price']=$insertOrder['total_price']-$coupon_price;  //优惠券抵用
        }
        //是否开启分销
        if($farmSetData['is_open_distribution']==1){
            $user=pdo_get('cqkundian_farm_user',array('uniacid'=>$uniacid,'uid'=>$uid));
            //当前下单用户的一级分销商
            if($user['one_distributor']!=0) {
                $insertOrder['is_price']=1;
                $one_sale = pdo_get('cqkundian_farm_user', array('uniacid' => $uniacid, 'uid' => $user['one_distributor']));
                $insertOrder['one_price']=round($insertOrder['total_price']*($farmSetData['distribution_one_price']/100),2);
                if($one_sale['one_distributor']!=0){
                    $insertOrder['two_price']=round($insertOrder['total_price']*($farmSetData['distribution_two_price']/100),2);
                }
            }
        }

        $order_res=pdo_insert('cqkundian_farm_group_order',$insertOrder);
        $order_id=pdo_insertid();
        //商品详情
        $insertDetail=array(
            'goods_id'=>$goods_id,
            'order_id'=>$order_id,
            'goods_name'=>$goodsData['goods_name'],
            'price'=>$goodsData['price'],
            'count'=>$count,
            'spec_id'=>$spec_id,
            'uniacid'=>$uniacid,
            'cover'=>$goodsData['cover'],
        );
    }
    $detail_res=pdo_insert('cqkundian_farm_group_order_detail',$insertDetail);
    if($order_res && $detail_res){
        if($coupon_id && $coupon_price){
            //修改优惠券使用
            pdo_update('cqkundian_farm_user_coupon',array('status'=>1),array('uniacid'=>$uniacid,'uid'=>$uid,'cid'=>$coupon_id));
        }
        echo json_encode(array('code'=>1,'order_id'=>$order_id));die;
    }else{
        echo json_encode(array('code'=>2));die;
    }
}

//组团购物支付回调
if($op=='notify'){
    $order_id=$_GPC['order_id'];
    $prepay_id_str=$_GPC['prepay_id'];
    $orderData=pdo_get('cqkundian_farm_group_order',array('id'=>$order_id,'uniacid'=>$uniacid));
    if($orderData['status']==6) {
        //更新商品的销量
        updateSaleCount($order_id, $uniacid);
        //更新商品库存
        updateGoodsCount($order_id, $uniacid);
        insertIntegral($uniacid, $order_id);
        //向用户推送消息
        $prepay_id = explode('=', $prepay_id_str);
        $wxData = pdo_get('cqkundian_farm_wx_set', array('uniacid' => $uniacid));
        include 'function.inc.php';
        $page = '/kundian_farm/pages/shop/Group/orderList/index';
        $res_user_send = send_msg_to_user($orderData, $prepay_id[1], $_W['openid'], $uniacid, $page);
        //给店家推送消息
        $wx_openid = unserialize($wxData['get_openid']);
        for ($i = 0; $i < count($wx_openid); $i++) {
            $res_send_shop = send_template_message($wx_openid[$i], $orderData, $uniacid);
        }
        echo json_encode(array('code' => 1));
        die;
    }else{
        echo json_encode(array('code' => 2));
        die;
    }
}

if($op=='getGroupList'){
    if(empty($_GPC['page'])){
        $page=1;
    }else{
        $page=$_GPC['page']+1;
    }
    $current=$_GPC['status'];
    $condition=array();
    if($current==2){
        $condition['status']=0;
    }elseif($current==3){
        $condition['status']=array('1,2,3');
    }elseif($current==4){
        $condition['status']=2;
    }
    $condition['uniacid']=$uniacid;
    $condition['use_is_delete']=0;
    $condition['uid']=$uid;
    $orderData=pdo_getall('cqkundian_farm_group_order',$condition,'','','create_time desc',array($page,10));
    $setData=pdo_get('cqkundian_farm_set',array('ikey'=>'expire_order_time','uniacid'=>$uniacid));
    for($n=0;$n<count($orderData);$n++){
        //判断订单支付时间是否过期
        if(!empty($setData) && $setData['value']!=0&& $setData['value']>0) {
            if($orderData[$n]['status']==0){
                if($orderData[$n]['create_time']+$setData['value'] <= time()){
                    pdo_update('cqkundian_farm_group_order',array('status'=>5),array('uniacid'=>$uniacid,'id'=>$orderData[$n]['id']));
                }
            }
        }

        $order_detail=pdo_getall('cqkundian_farm_group_order_detail',array('uniacid'=>$uniacid,'order_id'=>$orderData[$n]['id']));
        for ($i = 0; $i < count($order_detail); $i++) {
            $specVal = pdo_get('cqkundian_farm_group_goods_spec', array('goods_id' => $order_detail[$i]['goods_id'], 'uniacid' => $uniacid));
            $spec_id = explode(",", $specVal['sku_name']);
            $spec_val = pdo_getall('cqkundian_farm_group_spec_value', array('id in' => $spec_id));
            $specItem = pdo_getall('cqkundian_farm_group_spec', array('goods_id' => $order_detail[$i]['goods_id'], 'uniacid' => $uniacid));
            for ($j = 0; $j < count($specItem); $j++) {
                for ($m = 0; $m < count($spec_val); $m++) {
                    if ($specItem[$j]['id'] == $spec_val[$m]['spec_id']) {
                        $specItem[$j]['spec_value'] = $spec_val[$m]['spec_value'];
                    }
                }
            }
            $order_detail[$i]['specItem'] = $specItem;
        }
        $orderData[$n]['order_detail']=$order_detail;
    }

    echo json_encode(array('orderData'=>$orderData));die;
}

//订单申请退款
if($op=='applyGroupRefund'){
    $order_id=$_GPC['order_id'];
    $orderData=pdo_get('cqkundian_farm_group_order',array('id'=>$order_id,'uniacid'=>$uniacid));
    $res=pdo_update('cqkundian_farm_group_order',array('status'=>4),array('uniacid'=>$uniacid,'id'=>$order_id));
    if($res){
        include 'function.inc.php';
        $wxData=pdo_get('cqkundian_farm_wx_set',array('uniacid'=>$uniacid));
        $wx_openid=unserialize($wxData['get_openid']);
        for ($i=0;$i<count($wx_openid);$i++){
            $res_send_shop=cancelOrderSendTemplate($wx_openid[$i],$orderData,$uniacid);
        }
        echo json_encode(array('code'=>1));die;
    }else{
        echo json_encode(array('code'=>2));
    }
}

//确认收货
if($op=='sureGoods'){
    $order_id=$_GPC['order_id'];
    $orderData=pdo_get('cqkundian_farm_group_order',array('uniacid'=>$uniacid,'id'=>$order_id));
    //判断当前订单是否需要发放佣金
    $update_order=array(
        'status'=>3,
    );
    if($orderData['is_price']==1){
        include 'function.inc.php';
        $result=saleSendPirce($orderData,$uniacid,2);
        if($result){
            //修改佣金发放状态
            $update_order['is_price']=2;
        }
    }
    $res=pdo_update('cqkundian_farm_group_order',$update_order,array('uniacid'=>$uniacid,'id'=>$order_id));
    echo $res ? json_encode(array('code'=>1)):json_encode(array('code'=>2));die;
}

if($op=='cancelOrder'){
    $order_id=$_GPC['order_id'];
    $res=pdo_update('cqkundian_farm_group_order',array('status'=>5),array('uniacid'=>$uniacid,'id'=>$order_id));
    echo $res ? json_encode(array('code'=>1)):json_encode(array('code'=>2));die;   
}

//删除订单
if($op=='deleteOrder'){
    $orderid=$_GPC['orderid'];
    $uid=$_GPC['uid'];
    $res=pdo_update('cqkundian_farm_group_order',array('use_is_delete'=>1),array('uniacid'=>$uniacid,'uid'=>$uid,'id'=>$orderid));
    echo $res  ? json_encode(array('code'=>1,'msg'=>'删除成功')) : json_encode(array('code'=>2,'msg'=>'删除失败'));die;
}

/**
 * 更新商品销量
 * @param  [type] $order_id [description]
 * @param  [type] $uniacid  [description]
 * @return [type]           [description]
 */
function updateSaleCount($order_id,$uniacid){
    $orderData=pdo_get('cqkundian_farm_group_order',array('id'=>$order_id,'uniacid'=>$uniacid));
    $orderDetail=pdo_getall('cqkundian_farm_shop_group_detail',array('order_id'=>$order_id,'uniacid'=>$uniacid));
    for($i=0;$i<count($orderDetail);$i++){
        $goods_where=array(
            'id'=>$orderDetail[$i]['goods_id'],
            'uniacid'=>$uniacid,
        );
        pdo_update('cqkundian_farm_group_goods',array('sale_count +='=>$orderDetail[$i]['count']),$goods_where);
    }
}

/**
 * 更新商品库存
 * @param  [type] $orderid [description]
 * @param  [type] $uniacid [description]
 * @return [type]          [description]
 */
function updateGoodsCount($orderid,$uniacid){
    $orderData=pdo_get('cqkundian_farm_group_order',array('id'=>$orderid,'uniacid'=>$uniacid));
    $orderDetail=pdo_get('cqkundian_farm_group_order_detail',array('order_id'=>$orderid,'uniacid'=>$uniacid));
    $specVal=pdo_get('cqkundian_farm_group_goods_spec',array('id'=>$orderDetail['spec_id']));
    if($orderDetail['spec_id']!=0){
        pdo_update('cqkundian_farm_group_goods_spec',array('count -='=>$orderDetail['count']),array('id'=>$orderDetail['spec_id'],'uniacid'=>$uniacid));
    }else{
        pdo_update('cqkundian_farm_group_goods',array('count -='=>$orderDetail['count']),array('id'=>$orderDetail['goods_id'],'uniacid'=>$uniacid));
    }
    //插入组团信息
    $userData=pdo_get('cqkundian_farm_user',array('uid'=>$orderData['uid'],'uniacid'=>$uniacid));
    $insertGroup=array(
        'order_id'=>$orderid,
        'goods_id'=>$orderDetail['goods_id'],
        'uid'=>$orderData['uid'],
        'avatarurl'=>$userData['avatarurl'],
        'nickname'=>$userData['nickname'],
        'uniacid'=>$uniacid,
    );
    pdo_insert('cqkundian_farm_group',$insertGroup);
    changeGroupSuccess($orderDetail['goods_id'],$uniacid);
}

/**
 * 添加积分记录
 * @param $uniacid
 * @param $uid
 * @param $score
 */
function insertIntegral($uniacid,$order_id){
    $orderData=pdo_get('cqkundian_farm_group_order',array('id'=>$order_id,'uniacid'=>$uniacid));
    $aboutData=pdo_get('cqkundian_farm_about',array('uniacid'=>$uniacid));
    $userData=pdo_get('cqkundian_farm_user',array('uid'=>$orderData['uid'],'uniacid'=>$uniacid));
    $score=round($orderData['total_price']/$aboutData['pay_integral']);
    pdo_update('cqkundian_farm_user',array('score +='=>$score),array('uid'=>$orderData['uid'],'uniacid'=>$uniacid));
    $insertData=array(
        'uid'=>$orderData['uid'],
        'uniacid'=>$uniacid,
        'create_time'=>time(),
        'score_type'=>1,
        'score'=>$score,
        'body'=>$orderData['body'],
        'now_score'=>$userData['score']+$score,
    );
    pdo_insert('cqkundian_farm_integral_record',$insertData);
}


/**
 * 修改组团信息
 * @param  [type] $goods_id [description]
 * @param  [type] $uniacid  [description]
 * @return [type]           [description]
 */
function changeGroupSuccess($goods_id,$uniacid){
    $groupData=pdo_getall('cqkundian_farm_group',array('goods_id'=>$goods_id,'uniacid'=>$uniacid,'status'=>0));
    $specVal=pdo_getall('cqkundian_farm_group_goods_spec',array('goods_id'=>$goods_id,'uniacid'=>$uniacid));
    if($specVal){   //存在规格
        $allCount=0;
        for($i=0;$i<count($specVal);$i++){
            $allCount+=$specVal[$i]['count'];
        }
        if($allCount<=0){  //所有规格卖完
            for($j=0;$j<count($groupData);$j++){
                //修改组团状态
                pdo_update('cqkundian_farm_group_order',array('status'=>1),array('id'=>$groupData[$j]['order_id'],'uniacid'=>$uniacid));
                //修改组团状态
                pdo_update('cqkundian_farm_group',array('status'=>1),array('id'=>$groupData[$j]['id'],'uniacid'=>$uniacid));
            }
        }
    }else{  //不存在规格
        $goodsData=pdo_get('cqkundian_farm_group_goods',array('id'=>$goods_id,'uniacid'=>$uniacid));
        if($goodsData['count']<=0){
            for($j=0;$j<count($groupData);$j++){
                //修改组团状态
                pdo_update('cqkundian_farm_group_order',array('status'=>1),array('id'=>$groupData[$j]['order_id'],'uniacid'=>$uniacid));
                //修改组团状态
                pdo_update('cqkundian_farm_group',array('status'=>1),array('id'=>$groupData[$j]['id'],'uniacid'=>$uniacid));
            }
        }
    }
}









